package com.itheima.service.system.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.common.utils.UtilFuns;
import com.itheima.dao.system.SysLogDao;
import com.itheima.domain.system.SysLog;
import com.itheima.service.system.ISysLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysLogServiceImpl implements ISysLogService {

    @Autowired
    private SysLogDao sysLogDao;

    //查询系统访问压力
    @Override
    public List findOnlineData() {
        return sysLogDao.findOnlineData();
    }

    /**
     * 分页查询日志信息
     *
     * @param companyId
     * @param page
     * @param
     * @return
     */
    @Override
    public PageInfo findAll(String companyId, int page) {

        int size = 5;

        PageHelper.startPage(page, size);

        List<SysLog> logList = sysLogDao.findAll(companyId);

        return new PageInfo(logList);

    }

    /**
     * 保存日志
     *
     * @param log
     * @return
     */
    @Override
    public int save(SysLog log) {
        log.setId(UtilFuns.generateId());
        return sysLogDao.save(log);
    }
}
